//
//  FZWelcomeViewController.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/23/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit

class FZWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
        setupLayout()
        
    }
    
//MARK:==========================出场动画==========================
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        headerIMGView.snp_updateConstraints { (make) in
            
            make.top.equalTo(100)
            
        }
        
        UIView.animateWithDuration(1.2, delay: 0.5, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            
                self.view.layoutIfNeeded()
            
            }) { (_) in
                UIView .animateWithDuration(1, animations: {
                    self.nameLabel.alpha = 1
                    }, completion: { (_) in
                    
                        
                    NSNotificationCenter.defaultCenter().postNotificationName(FZSWITCHROOTVIEWCONTROLLER, object: "welcomeView")
                })
        }
        
    }

    
//MARK:==========================加载控件/布局==========================
    func setupUI() {
        
        view.addSubview(backIMGView)
        view.addSubview(headerIMGView)
        view.addSubview(nameLabel)
        
    }
    func setupLayout(){
        
        backIMGView.snp_makeConstraints { (make) in
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
        }
        
        headerIMGView.snp_makeConstraints { (make) in
            make.top.equalTo(view.snp_top).offset(350)
            make.size.equalTo(CGSizeMake(90, 90))
            make.centerX.equalTo(view)
        }
        nameLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headerIMGView.snp_bottom).offset(16)
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    lazy var backIMGView: UIImageView = UIImageView(imgNamed: "ad_background")
    
    lazy var headerIMGView: UIImageView = {
        
       let userAccount = FZUserAccountViewModel.sharedUserAcount.userAccount
        let urlString = userAccount?.avatar_large ?? ""
        let imageView: UIImageView = UIImageView.init()
        imageView.fz_setImage(urlString)
        
        imageView.layer.cornerRadius = 45
        imageView.layer.masksToBounds = true
        imageView.layer.borderColor = UIColor.orangeColor().CGColor
        imageView.layer.borderWidth = 2
        
        return imageView
    }()
    
    lazy var nameLabel: UILabel = {
        
        let lb: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 14)
        lb.text = "欢迎回来"
        lb.alpha = 0
        return lb
    }()

}
